package com.zhia.demo.controller;

import com.zhia.demo.entity.RecoverEntity;
import com.zhia.demo.service.RecoverService;
import com.zhia.demo.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.thymeleaf.util.StringUtils;

import java.sql.Timestamp;
import java.util.Date;

/**
 * @author DONG
 * @create 2023/11/4 22:58
 */
@RestController
public class RecoverController {
    @Autowired
    private RecoverService recoverService;

    @PostMapping("/recover/save")
    private ResultVo save(RecoverEntity recoverEntity, @CookieValue(name = "USERSESSION", defaultValue = "") String cookie) {
        if (!StringUtils.isEmpty(cookie)) {
            recoverEntity.setUserId(Integer.parseInt(cookie));
        }
        ResultVo resultVo = new ResultVo();
        try {
            recoverService.addRecover(recoverEntity);
        } catch (Exception e) {
            resultVo.setCode(1L);
            resultVo.setMessage("该评论已删除");
        }
        return resultVo;
    }

    @DeleteMapping("recover/{id}")
    private void delete(@PathVariable("id") Integer id) {
        recoverService.removeById(id);
    }

}
